<template>
  <div class="search">
    <van-search
      v-model="selectParams.key"
      placeholder="请输入搜索关键词"
      clearable
      @search="onSearch"
      @clear="onSearch"></van-search>
    <van-dropdown-menu>
      <van-dropdown-item title="筛选" ref="item">
        <task-filter-panel @search="onFilterPanelSearch"></task-filter-panel>
      </van-dropdown-item>
    </van-dropdown-menu>
  </div>
</template>
<script>
import TaskFilterPanel from './TaskFilterPanel.vue'
export default {
  name: 'TaskHead',
  components: { TaskFilterPanel },
  props: {},
  data() {
    return {
      selectParams: {
        startTime: '',
        endTime: '',
        key: '',
        taskSource: '',
        taskStatus: '',
        taskType: '',
        assessmentCoefficient: '',
        assessmentCycle: '',
        feedbackCycleType: '',
        feedbackCycleVal: '',
        taskClassify: '',
      },
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    /* 筛选 */
    onSearch() {
      this.$emit('search', this.selectParams)
    },
    /* 筛选面板选中数据 */
    onFilterPanelSearch(data) {
      this.selectParams.userId = ''
      for (const key in data) {
        if (Object.hasOwnProperty.call(data, key)) {
          const element = data[key]
          if (key === 'cycleCfgVOS') {
            // 反馈周期
            this.selectParams.feedbackCycleType = element.objType ? element.objType : element.id
            this.selectParams.feedbackCycleVal = element.objType ? element.id : ''
          } else if (key === 'orgIds') {
            // 机构信息
            this.selectParams.orgId = element.id
          } else if (key === 'taskClassifyVOS') {
            // 任务分类
            this.selectParams.taskClassify = element.id
          } else if (key === 'children') {
            // 机构信息-人员信息
            this.selectParams.userId = element.id
          } else {
            if (key === 'assessmentCycle') {
              if (!element.id || !element.id.startsWith('ASSESSMENT_CYCLE_')) {
                this.selectParams.isAssessment = ''
              } else {
                if (element.id === 'ASSESSMENT_CYCLE_NO') {
                  this.selectParams.isAssessment = '0'
                } else {
                  this.selectParams.isAssessment = '1'
                }
              }
            }
            // this.selectParams[key] = element.taskType || element.objId
            this.selectParams[key] = element.id
          }
        }
      }
      this.$refs.item.toggle()
      this.onSearch()
    },
  },
}
</script>
<style lang="scss" scoped>
.search {
  display: flex;
  /deep/.van-dropdown-menu {
    width: 20%;
  }
  /deep/.van-dropdown-menu__bar {
    box-shadow: none;
  }
  .van-search {
    padding: 10px 0 10px 12px;
    flex: 1;
  }
  /deep/.van-popup {
    overflow: hidden;
  }
  /deep/.van-search__content {
    padding-left: 12px;
  }
}
</style>
